<template>
  <RTHeader label="面试环节" :statusInfo="statusInfo"></RTHeader>
  <div class="wrap">
    <span>面试结果通知时间 </span>
    <a-date-picker class="datepicker" :status="!interviewSendTime ? 'error' : ''" :date-format="'YYYY-MM-DD HH:mm'"
      :format="'YYYY-MM-DD HH:mm'" :disabled-date="disabledDate" :value-format="'YYYY-MM-DD HH:mm'" style="width: 100%;"
      v-model:value="interviewSendTime" placeholder="面试结果通知时间" :show-time="{ format: 'HH:mm', minuteStep: 5 }" />
      <a-checkbox class='ml-30px' v-model:checked="isSendEmail">发送邮件通知</a-checkbox>
  </div>
  <a-textarea v-model:value="reason" @input="setLocal" placeholder="请填写面试评价" :autoSize="{ minRows: 4, maxRows: 4 }" />
  <div class="btns">
    <Button v-auth="'arriveInterviewProgress'" color="success" @click="pass">通过</Button>
    <Button v-auth="'arriveInterviewEliminate'" color="error" @click="dieOut">淘汰</Button>
    <Button v-auth="'arriveInterviewWaive'" color="warning" @click="surrender">放弃</Button>
  </div>
</template>
<script setup lang='ts'>
import { ref, onMounted } from "vue";
import { Button } from "@/components/Button";
import RTHeader from '../../RTHeader.vue';
import { message } from "ant-design-vue";
import { arriveSchedule } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
const store = comStores()
const disabledDate = (current: any) => {
  // Can not select days before today and today
  return current && current < new Date().setHours(0, 0, 0, 0);
};
const interviewSendTime = ref<any>("")
  const isSendEmail =ref<boolean>(true)
const { userName } = store.userInFor
// 
const reason = ref<string>("");
onMounted(() => {
  reason.value = localStorage.getItem('面试评价') || ""
})
const statusInfo = ref({
  status: "到面-待面试",
  hr: "王xx",
  count: 1
})
const emits = defineEmits(['surrender', 'changeDate',])
const surrender = async () => {
  if (!interviewSendTime.value) return
  localStorage.setItem('面试评价', "");
  // console.log('surrender')
  if (reason.value.trim() == "") return message.error("面试评价不能为空")
  const { resumeId, processId } = store.currentResume;
  // emits('surrender', '到面')
  let param = {
    resumeId: resumeId,
    processId: processId,
    assess: reason.value,
    result: "放弃",
    operator: userName,
    interviewSendTime: interviewSendTime.value + ':00',
    isSend:isSendEmail.value
  }
  const data = await arriveSchedule(param);
  if (data && data.code === '10000') {
    message.success("操作成功")
    store.getResumeInfo(resumeId);
  } else {
    message.error(data.msg)
  }
}

const dieOut = async () => {
  if (!interviewSendTime.value) return
  localStorage.setItem('面试评价', "");
  if (reason.value.trim() == "") return message.error("面试评价不能为空")
  const { resumeId, processId } = store.currentResume;
  let param = {
    resumeId: resumeId,
    processId: processId,
    assess: reason.value,
    result: "淘汰",
    operator: userName,
    interviewSendTime: interviewSendTime.value + ':00',
    isSend:isSendEmail.value
  }
  const data = await arriveSchedule(param);
  if (data && data.code === '10000') {
    message.success("操作成功")
    store.getResumeInfo(resumeId);
  } else {
    message.error(data.msg)
  }
}

const pass = async () => {
  if (!interviewSendTime.value) return;
  localStorage.setItem('面试评价', "");
  if (reason.value.trim() == "") return message.error("面试评价不能为空")
  const { resumeId, processId } = store.currentResume;
  let param = {
    resumeId: resumeId,
    processId: processId,
    assess: reason.value,
    result: "通过",
    operator: userName,
    interviewSendTime: interviewSendTime.value + ':00',
    isSend:isSendEmail.value
  }
  const data = await arriveSchedule(param);
  if (data && data.code === '10000') {
    message.success("操作成功")
    store.getResumeInfo(resumeId);
  } else {
    message.error(data.msg)
  }
}
const setLocal = () => {
  localStorage.setItem('面试评价', reason.value);
}
</script>
<style lang="less" scoped>
.btns {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.wrap {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  color: #333;
  width: 528px;

  span {
    width: 125px;
    font-size: 14px;
    position: relative;

    &:after {
      content: "*";
      position: absolute;
      right: 6px;
      top: -4px;
      z-index: 100;
      color: red;
    }
  }

  .datepicker {
    flex: 1;
  }
}
</style>